<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<table width="100%" border="0" cellspacing="0" class="table_padding">
	<tr>
		<td align="center">
			<table border="0" cellpadding="0" cellspacing="0" class="table_border">
				<tr>
					<td align="center">
						<form id="selectUserPageForm">
							<table border="0" cellpadding="0" cellspacing="0" class="box_table" id="box_table">
								<tr>
									<td width="22%">&nbsp;用户姓名：<input name="name" type="text" /></td>
									<td width="38%">
										失效时间：<input type="text" name="startTime"  class="Wdate" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="20" />
										至 <input class="Wdate" name="endTime" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" size="20" />
									</td>
									<td width="25%">锁定状态：
										<input type="radio" name="status" value="0" style="vertical-align: middle;"/> 锁定
										<input type="radio" checked name="status" value="1" style="vertical-align: middle;"/> 启用
									</td>
									<td>
										<a class="button" onclick="pageSelect()" href="javascript:void(0)"><span>查询</span></a>
									</td>
								</tr>
							</table>
						</form>
					</td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="0" class="table_border">
				<tr>
					<td>
						<table style="position : relative;left : 5px; top : 5px;">
							<tr>
								<td width="75px" align="right">
									<a class="button" onclick="commont('detail')" href="javascript:void(0)" ><span>查看明细</span></a>
								</td>
								<td width="50px">
									<a class="button" href="forwordPage?pagePath=user/add.jsp"><span>新增</span></a>
								</td>
								<td width="50px">
									<a class="button" onclick="deleteUser()" href="javascript:void(0);"><span>删除</span></a>
								</td>
								<td width="50px">
									<a class="button" onclick="commont('edit')"><span>修改</span></a>
								</td>
								<td width="50px">
									<a onclick="startAndStop(1)" class="button"><span>启用</span></a>
								</td>
								<td width="50px">
									<a onclick="startAndStop(0)" class="button"><span>锁定</span></a>
								</td>
								<td width="70px">
									<a class="button" onclick="toAssign()" href="javascript:void(0)"><span>分配角色</span></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td height=110>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td align="center">
									<table border="0" cellpadding="0" cellspacing="0"
										id="box_num_table2" class="box_num_table">
										<thead>
											<tr>
												<td width="8%"><input type="checkbox" /></td>
												<td width="7%">序号</td>
												<td width="12%">登录帐号</td>
												<td width="11%">用户姓名</td>
												<td width="12%">创建时间</td>
												<td width="13%">失效时间</td>
												<td width="11%">允许访问IP</td>
												<td width="11%">状态</td>
											</tr>
										</thead>
										<tbody id="tInfo2">
											<%--<tr class="odd">
												<td><input type="checkbox" /></td>
												<td>1</td>
												<td>zhangsan</td>
												<td>张三</td>
												<td>2012-04-13 10:47:28</td>
												<td>2012-04-13 10:47:28</td>
												<td>192.168.1.100，192.168.1.101</td>
												<td>锁定</td>
											</tr>
											<tr class="odd">
												<td><input type="checkbox" /></td>
												<td>2</td>
												<td>lisi</td>
												<td>李四</td>
												<td>2012-04-13 10:47:28</td>
												<td>2012-04-13 10:47:28</td>
												<td>192.168.1.100，192.168.1.101</td>
												<td>启用</td>
											</tr>--%>
										</tbody>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="0" class="table_border">
                <tr>
                    <td>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0"
                               class="table_padding">
                            <tr>
                                <td width="8%" class="font_left">数据:<span id="totalNumber">200</span>条</td>
                                <td width="12" class="font_left">第</td>
                                <td width="375" class="font_left">
                                    <input name="textfield2" id="index" type="text" size="2" maxlength="4" /> /<span id="pageCount">5</span>页
                                </td>
                                <td width="478" class="font_right">
                                    <a id="first" href="javascript:void(0)">首页</a>
                                    <a id="previousPage" href="javascript:void(0)">上一页</a>
                                    <a id="nextPage" href="javascript:void(0)">下一页</a>
                                    <a id="end" href="javascript:void(0)">末页</a>
                                    <a href="">刷新</a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
		</td>
	</tr>
</table>
<script>
	pageSelect();
	/*$.post("/SSM_OA_YJF_war_exploded/userController/getUserPage",{current:1,size:5},function (data) {
		console.log(data);
		let records = data.records;
		var str = '';
		for (let i = 0; i < records.length; i++) {
			var allowIps = (data.records[i].allowIps==null)?"无":data.records[i].allowIps;
			var expireTime = (data.records[i].expireTime==null)?"无":data.records[i].expireTime;
			var lockStatus = (data.records[i].lockStatus==1)?"启用":"停用";
			str += '<tr class="odd">' +
					'<td><input type="checkbox" class="userCheck" value="'+data.records[i].id+'" /></td>' +
					'<td>'+(i+1)+'</td>' +
					'<td>'+data.records[i].accountNo+'</td>' +
					'<td>'+data.records[i].name+'</td>' +
					'<td>'+data.records[i].createTime+'</td>' +
					'<td>'+expireTime+'</td>' +
					'<td>'+allowIps+'</td>' +
					'<td>'+lockStatus+'</td>' +
					'</tr>';

		}
		$("#tInfo2").append(str);
	});*/

	//删除用户
	function deleteUser() {
		if($(":checkbox[class='userCheck']:checked").length!=1){
			alert("请选择一个用户！！")
		}else {
			$.post("deleteUserByUid",{uid:$(":checkbox[class='userCheck']:checked").val()},function (data) {
				console.log(data);
				if(data.status==true){
					$(":checkbox[class='userCheck']:checked").parent().parent().remove();
				}
			});
		}
	}

	//跳转页面
	function commont(url) {
		if($(":checkbox[class='userCheck']:checked").length!=1){
			alert("请选择一个用户！！")
		}else {
			document.location.href = "toUserParticulars?id="+$(":checkbox[class='userCheck']:checked").val()+"&url="+url;
		}
	}

	//修改状态
	function startAndStop(status) {
		if($(":checkbox[class='userCheck']:checked").length!=1){
			alert("请选择一个用户！！");
		}else {
			$.post("updatelockStatus",{uid:$(":checkbox[class='userCheck']:checked").val(),status:status},function (data) {
				$(":checkbox[class='userCheck']:checked").parent().parent().children("td:last").text(status==1?'启用':'锁定');
				console.log(data);
				$(":checkbox[class='userCheck']:checked").prop("checked",false);
			});
		}
	}

	function pageSelect(index=1,size=5) {
		$.post("selectUserPage",$("#selectUserPageForm").serialize()+"&index="+index+"&size="+size,function (data) {
			console.log(data);
			let st = ``;
			for (let i = 0; i < data.list.length; i++) {
				let allowIps = (data.list[i].allowIps==null)?"无":data.list[i].allowIps;
				let createTime = (data.list[i].createTime==null)?"无":data.list[i].createTime;
				let expireTime = (data.list[i].expireTime==null || data.list[i].expireTime=='')?"无":data.list[i].expireTime;
				st += `
						<tr class="odd">
							<td><input class="userCheck" value="\${data.list[i].id}" type="checkbox" /></td>
							<td>\${i+1}</td>
							<td>\${data.list[i].accountNo}</td>
							<td>\${data.list[i].name}</td>
							<td>\${createTime}</td>
							<td>\${expireTime}</td>
							<td>\${allowIps}</td>
							<td>\${data.list[i].lockStatus==1?'启用':'锁定'}</td>
						</tr>
					`;
			}
			$("#tInfo2").html(st);
			$("#index").val(data.index);
			$("#totalNumber").text(data.totalNumber);
			$("#pageCount").text(data.pageCount);

		});
	}

	$("#first").click(function () {
		pageSelect();
	})
	$("#previousPage").click(function () {
		if($("#index").val()>1){
			pageSelect($("#index").val()-1);
		}
	})
	$("#nextPage").click(function () {
/*		let newVar = $("#index").val()<$("#pageCount").text()?parseInt($("#index").val())+1:$("#pageCount").text();*/
		if($("#index").val()<$("#pageCount").text()){
			pageSelect(parseInt($("#index").val())+1);
		}
	})
	$("#end").click(function () {
		pageSelect($("#pageCount").text());
	})

	function toAssign() {
		if($(":checkbox[class='userCheck']:checked").length!=1){
			alert("请选择一个用户！！");
		}else {
			location.href = "toUserParticulars?url=assign&id="+$(":checkbox[class='userCheck']:checked").val();
		}

	}
</script>
